<template>
  <div class="main">
    <el-dialog title="工作任务指派" width="80%" :visible.sync="dialogFormVisible">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
      <el-form-item label-width="0">
          <el-row>
            <div class="m-wrap">
              <div class="work-title" style="width:25%;">子任务名称</div>
              <div class="work-title" style="width:40%;">工作内容描述</div>
              <div class="work-title" style="width:100px;">标准分</div>
              <div class="work-title" style="width:200px;">小组成员</div>
            </div>
          </el-row>
      </el-form-item>
      <el-form-item label-width="0" v-for="(w, n) in works"
            :key="'w_' + n">
          <div
            class="m-wrap"
          >
          <el-input
            v-model="w.workName"
            placeholder="子任务名称" style="width:25%"
            readonly="readonly"
          ></el-input>
          <el-input
            type="textarea"
            v-model="w.workDetail"
            maxlength="400"
            placeholder="子任务内容描述" style="width: 40%;margin-left: 20px;"
            rows="2"
            readonly="readonly"
            show-word-limit
          ></el-input>
            <el-input-number
              v-model="w.scoreStd"
              :min="1"
              controls-position="right"
              placeholder="标准分"
              style="width: 100px;margin-left: 20px;"
              readonly="readonly"
            ></el-input-number>
          <el-select
          v-model="w.executor"
          placeholder="请选择小组成员"
          style="width:200px; margin-left: 20px;"
          >
            <el-option
              v-for="item in members"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
          </el-option>
        </el-select>          
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeForm">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >提交</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { assignTask, listMembers } from "@/api/system/task";
export default {
  name: "addform",
  data() {
    return {
      dialogFormVisible: false,
      formLabelWidth: "120px",
      projectManagerArr: [],
      ruleForm: {},
      works:[],
      rules: {
      },
      members:[]
    };
  },
  mounted() {
    
  },
  methods: {
    getMembers(){
      listMembers({leader: this.ruleForm.leader}).then(resp=>{
        this.members = resp.data;
      });
    },
    open() {
      this.getMembers();
      this.dialogFormVisible = true;
    },
    closeForm() {
      this.resetForm("ruleForm");
      this.dialogFormVisible = false;
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.ruleForm.details = this.works;
          
          assignTask(this.ruleForm)
            .then(res => {
              // console.log(res);
              if (res.code == 200) {
                this.resetForm(formName);
                this.dialogFormVisible = false;
                this.$parent.init();
              }
            })
            .catch(error => {
            });
            
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
};
</script>

<style scoped lang="scss">
.tip{
  font-size: 12px;
    color: #606266;
    margin-top: 7px;
}
.work-title{
  text-align:center;float:left;margin-left: 20px;
}
</style>
